package com.ysd.Dao.Impl;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ysd.entity.Admin;
import com.ysd.util.DBmanager;

public class AdminDaoImpl {
	public Admin getAdminByUserName(String userName) {
		 Connection conn= DBmanager.getConnection();
		 Statement st =null;
		 ResultSet  rs=null;
		 try {
			 Admin admin = null;
			 st = conn.createStatement();
			 String sql = "SELECT * FROM admin where userName='"+userName+"' ";
			 rs = st.executeQuery(sql);
			 while(rs.next()) {
				 int id = rs.getInt(1);
				 String uName = rs.getString(2);
				 String password = rs.getString(3);
				 admin = new Admin(id,uName,password);
			 }
			 return admin;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBmanager.closeAll(conn, st, rs);
		}
	}
}
